package com.sh.链表;

import java.util.HashMap;

/**
 * @Auther: sh
 * @Version 1.0
 * @Description:
 */
public class 相交链表 {
    public static void main(String[] args) {

    }


    public static ListNode getIntersectionNode(ListNode headA, ListNode headB) {
//        ListNode a = headA;
//        ListNode b = headB;
//        while (a != b) {
//            a = a == null ? headB : a.next;
//            b = b == null ? headA : b.next;
//        }
//        return b;


        HashMap<Object, Object> aMap = new HashMap<>();
        ListNode a = headA;
        ListNode b = headB;
        while (a!=null){
            aMap.put(a, a);
            a=a.next;
        }
        while (b!=null){
            if (aMap.containsKey(b)){
                return b;
            }
            b=b.next;
        }
        return null;


    }
}



